﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using DekstopVer.Transfer;

using System.IO;
using Microsoft.Win32;

namespace DekstopVer
{
    /// <summary>
    /// Interaction logic for UploadFile.xaml
    /// </summary>
    public partial class UploadFile : Window
    {
        public UploadFile()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
             // Create OpenFileDialog
           OpenFileDialog dlg = new OpenFileDialog();

            
           
            // Set filter for file extension and default file extension
            dlg.Filter = "Word Documents|*.doc|Excel Worksheets|*.xls|PowerPoint Presentations|*.ppt" +
                      "|Office Files|*.doc;*.xls;*.ppt" +
                      "Images (*.bmp;*.jpeg;*.gif)|*.bmp;*.jpeg;*.gif|" +
                      "|All Files|*.*";

            // Display OpenFileDialog by calling ShowDialog method
           dlg.ShowDialog();

            
                // Open document
                string filename = dlg.FileName;
                FileNameTextBox.Text = filename;
                dlg.OpenFile().Close();
            
        

           
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            if (System.IO.File.ReadAllBytes(FileNameTextBox.Text) != null)
            {
                System.IO.FileInfo fileInfo =
                       new System.IO.FileInfo(FileNameTextBox.Text);
                TransferServiceClient clientUpload =
                        new TransferServiceClient();
                DekstopVer.Transfer.RemoteFileInfo
                       uploadRequestInfo = new DekstopVer.Transfer.RemoteFileInfo();

                using (System.IO.FileStream stream =
                       new System.IO.FileStream(FileNameTextBox.Text,
                       System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    uploadRequestInfo.FileName = FileNameTextBox.Text;
                    uploadRequestInfo.Length = fileInfo.Length;
                    uploadRequestInfo.FileByteStream = stream;
                    
                    clientUpload.UploadFile(uploadRequestInfo.FileName, uploadRequestInfo.Length, uploadRequestInfo.FileByteStream);
                    
                }
            }
        }


    }
}
